package cn.zxy.controller;

import cn.zxy.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.nio.channels.Pipe;
import java.util.ArrayList;
import java.util.List;

//@Controller
@RestController
//@RestController里面包含了@ResponseBody
//所以里面就可以不需@ResponseBody
@RequestMapping("/api")
public class BoyController {
    //返回纯字符串
   @GetMapping ("boy")
//    @ResponseBody
    public String boy(){

        return "我是boy的方法";
    }

    //如果返回值是数组的情况下怎么办
//    @GetMapping
    @GetMapping("strings")//标准写法
    @ResponseBody
    public  String[] strings(){
       return new String[]{"赵生蚝","撒娇","求抱抱"};
    }

    //使用集合
    @GetMapping("users")
    @ResponseBody
    public List<User> users(){
        List<User> list = new ArrayList<>();
        list.add(new User("赵生蚝","123456",180));
        list.add(new User("铁柱","111111",190));
        list.add(new User("侯铁柱","122222",200));
        return list;
    }

    //注册操作
    @GetMapping("register")
    public String register(){
       return "register";
    }

    @PostMapping("regok")
    public ModelAndView regok(String username,String password){
        System.out.println(username);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("success");
        mv.addObject("name",username);
        mv.addObject("pwd",password);
        return mv;
    }






}
